package com.puzzlebazar.client.squaregrid.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;


public class ConfirmationDialog extends DialogBox {

	public interface Callback {
		public void ok();
		public void cancel();
	}
	
	/**
	 * Creates a standard confirmation dialog
	 * 
	 * @param title The title of the dialog
	 * @param HTMLMessage The HTML message to display in the dialog
	 * @param OkText The text to place on the OK button
	 * @param CancelText The text to place on the Cancel button
	 * @param callback The callback to execute when the dialog is closed
	 */
	public ConfirmationDialog( String title, String HTMLMessage, 
			String OkText, String CancelText, 
			final Callback callback ) {
		
		setText( title );
		
		HorizontalPanel buttonPanel = new HorizontalPanel();
		buttonPanel.setWidth( "100%");
		buttonPanel.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
		
		VerticalPanel panel = new VerticalPanel();
		panel.setWidth( "100%" );
		
		panel.add( new HTML( HTMLMessage ) );
		panel.add( buttonPanel );
		
		
		Button okButton = new Button(OkText);
		okButton.setWidth( "60px" );
		
		Button cancelButton = new Button(CancelText);
		cancelButton.setWidth( "60px" );

		buttonPanel.add( okButton );
		buttonPanel.setCellWidth( okButton, "50%" );
		buttonPanel.add( cancelButton );
		buttonPanel.setCellWidth( cancelButton, "50%" );
		
		okButton.addClickHandler( new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				ConfirmationDialog.this.hide();
				callback.ok();
			}});

		cancelButton.addClickHandler( new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				ConfirmationDialog.this.hide();
				callback.cancel();
			}});
		
		setWidget(panel);		
		setAnimationEnabled(true);
	}

	
}
